using System;
using System.Collections.Generic;
using System.Text;

namespace Fuzzware.ConvertFromXML.Processors
{
    class ProcessorFnAssigner
    {
        /// <summary>
        /// Node processing functions should take in raw bytes, process them, encode the result back into the format of the node that
        /// holds the result (using Coder.EncodingType) and then encode that value into the output encoding 
        /// (SchemerGlobalInfo.OutputEncoding).  The value is written directly to the output as raw bytes.
        /// </summary>
        /// <param name="Command"></param>
        /// <param name="Value"></param>
        /// <param name="RefId"></param>
        /// <param name="Function"></param>
        public static void Assign(String Command, String Value, ref String RefId, ref NodeProcessor.NodeProcessingFn Function)
        {
            switch (Command)
            {
                case "ByteLength":
                    RefId = String.Copy(Value);
                    ByteLengthFn oByteLengthFn = new ByteLengthFn();
                    Function += oByteLengthFn.ByteLength;
                    break;
                case "WordLength":
                    RefId = String.Copy(Value);
                    WordLengthFn oWordLengthFn = new WordLengthFn();
                    Function += oWordLengthFn.WordLength;
                    break;
                case "CharLength":
                    RefId = String.Copy(Value);
                    CharLengthFn oCharLengthFn = new CharLengthFn();
                    Function += oCharLengthFn.CharLength;
                    break;
                case "Count":
                    RefId = String.Copy(Value);
                    CountFn oCountFn = new CountFn();
                    Function += oCountFn.Count;
                    break;
                case "KeepEndBytes":
                    KeepBytesFns oKeepEndBytesFns = new KeepBytesFns();
                    Function += oKeepEndBytesFns.KeepEndBytes;
                    break;
                case "KeepStartBytes":
                    KeepBytesFns oKeepStartBytesFns = new KeepBytesFns();
                    Function += oKeepStartBytesFns.KeepStartBytes;
                    break;
                case "CRC32":
                    RefId = String.Copy(Value);
                    //CRC32Fn oCRC32Fn = new CRC32Fn();
                    Function += CRC32Fn.CRC32;
                    break;
                //case "CRC32Len":
                //    Function += CRC32Fn.CRC32Len;
                //    break;
                case "UserCode":
                    RefId = String.Copy(Value);
                    Function += UserCodeFn.RunUserCode;
                    break;
                default:
                    break;
            }
        }
    }
}
